import request from '@/utils/request.js'

export const getComment = (articleId, offset) => {
  // 如果函数没有写return，
  //  它有一个默认的return值，就是undefined
  // return request({
  return request({
    url: 'v1_0/comments', // 接口地址
    method: 'GET',
    params: {
      type: 'a',
      source: articleId,
      offset
    }
  })
}

// 添加文章评论
export const addComment = (articleId, content) => {
  return request({
    method: 'POST',
    url: 'v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}

/**
 * 对文章评论进行点赞
 * @param {*} commentId 评论id
 */
export const addCommentLike = commentId => {
  return request({
    method: 'POST',
    url: 'v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}

/**
 * 取消文章评论的点赞
 * @param {*} commentId 评论id
 */
export const deleteCommentLike = commentId => {
  return request({
    method: 'DELETE',
    url: 'v1_0/comment/likings/' + commentId
  })
}
